/**   
* @Title: ClaimModelDao.java 
* @Package com.infodms.dms.dao.claim.basicData 
* @Description: TODO(车型组维护DAO) 
* @author wangjinbao   
* @date 2010-6-4 上午08:53:11 
* @version V1.0   
*/
package com.infodms.dms.dao.claim.basicData;

import java.sql.ResultSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.dao.common.BaseDao;
import com.infodms.dms.po.TtAsWrModelGroupPO;
import com.infoservice.po3.bean.PO;
import com.infoservice.po3.bean.PageResult;

/** 
 * @ClassName: ClaimModelDao 
 * @Description: TODO(车型组维护DAO) 
 * @author wangjinbao 
 * @date 2010-6-4 上午08:53:11 
 *  
 */
public class ClaimModelDao extends BaseDao {
	public static Logger logger = Logger.getLogger(ClaimModelDao.class);
	private static final ClaimModelDao dao = new ClaimModelDao ();
	public static final ClaimModelDao getInstance() {
		return dao;
	}
	
	/**
	 * 
	* @Title: claimModelQuery  
	* @Description: 车型组查询
	* @param  pageSize           ：每页显示条数
	* @param  curPage            ：当前页数
	* @param  whereSql           ：查询条件
	* @param  params             ：查询条件对应的参数
	* @param @throws Exception    设定文件 
	* @return PageResult<Map<String,Object>>    返回类型 
	* @throws
	*   
	 */
	@SuppressWarnings("unchecked")
	public   PageResult<Map<String, Object>> claimModelQuery(int pageSize, int curPage, String whereSql,List<Object> params,Long oemCompanyId) throws Exception {
		PageResult<Map<String, Object>> result = null;
		StringBuffer sb = new StringBuffer();
		sb.append(" select count(tg.model_id) as group_count,tg.wrgroup_id,tg.wrgroup_type,tg.wrgroup_code,tg.wrgroup_name,tg.free ");
		sb.append(" from (select tawmg.wrgroup_id,tawmg.wrgroup_type,tawmg.wrgroup_code,tawmg.wrgroup_name,tawmi.model_id, ");
		sb.append(" tawmg.oem_company_id,tawmg.free ");
		sb.append(" from TT_AS_WR_MODEL_GROUP tawmg left outer join TT_AS_WR_MODEL_ITEM tawmi ");
		sb.append(" on tawmg.wrgroup_id = tawmi.wrgroup_id ) tg ");
		sb.append(" group by tg.wrgroup_id,tg.wrgroup_type,tg.wrgroup_code,tg.wrgroup_name, ");
		sb.append(" tg.oem_company_id,tg.free ");
		sb.append(" having 1=1 ");
		sb.append(" and  tg.oem_company_id = "+oemCompanyId+" ");
		if(whereSql != null && !"".equals(whereSql.trim())){
			sb.append(whereSql);
		}
		sb.append(" order by tg.wrgroup_id desc ");
		result = (PageResult<Map<String, Object>>) pageQuery(sb.toString(), params, getFunName(), pageSize, curPage);
		return result;
	}
	/**
	 * 
	* @Title: claimModelUpdate 
	* @Description: TODO(车型组修改) 
	* @param @param selpo
	* @param @param updatepo   
	* @return void  
	* @throws
	 */
	@SuppressWarnings("unchecked")
	public void claimModelUpdate(TtAsWrModelGroupPO selpo,TtAsWrModelGroupPO updatepo){
		dao.update(selpo, updatepo);
	}
	/**
	 * 
	* @Title: getClaimModel 
	* @Description: TODO(取对应车型组的车型详细信息) 
	* @param @param id
	* @param @param type
	* @param @return   
	* @return List  
	* @throws
	 */
	@SuppressWarnings("unchecked")
	public List getClaimModel(Long id,Integer type){
		List<Object> params = new LinkedList<Object>();
		StringBuilder sb = new StringBuilder();
		sb.append(" select tvmg.group_code,tvmg.group_name from TM_VHCL_MATERIAL_GROUP tvmg ");
		sb.append(" where  tvmg.group_id in ( select tawmi.model_id ");
		sb.append(" from TT_AS_WR_MODEL_GROUP tawmg left outer join TT_AS_WR_MODEL_ITEM tawmi  ");
		sb.append(" on tawmg.wrgroup_id = tawmi.wrgroup_id ");
		sb.append("	where tawmg.wrgroup_id = ?  ");
		params.add(id);
		sb.append(" and tawmg.wrgroup_type = ? ");
		params.add(type);
		sb.append(" )");
		List<Map<String, Object>> list = pageQuery(sb.toString(), params, getFunName());
		return list;
	}

	/* (非 Javadoc) 
	 * <p>Title: wrapperPO</p> 
	 * <p>Description: </p> 
	 * @param rs
	 * @param idx
	 * @return 
	 * @see com.infodms.dms.dao.common.BaseDao#wrapperPO(java.sql.ResultSet, int) 
	 */
	@Override
	protected PO wrapperPO(ResultSet rs, int idx) {
		// TODO 自动生成方法存根
		return null;
	}

}
